package com.property.demo.repository;

import com.property.demo.model.ParkingUsage;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ParkingUsageRepository extends JpaRepository<ParkingUsage, Long>, JpaSpecificationExecutor<ParkingUsage> {
    
    // 按小区ID查询
    List<ParkingUsage> findByParking_Community_Id(Long communityId);
    
    // 按小区ID分页查询
    Page<ParkingUsage> findByParking_Community_Id(Long communityId, Pageable pageable);
    
    // 按车位ID查询
    List<ParkingUsage> findByParkingId(Long parkingId);
    
    // 按业主ID查询
    List<ParkingUsage> findByOwnerId(Long ownerId);
    
    // 按车辆ID查询
    List<ParkingUsage> findByVehicleId(Long vehicleId);
    
    // 按业主姓名模糊查询
    List<ParkingUsage> findByOwner_NameContaining(String ownerName);
    
    // 按车牌号模糊查询
    List<ParkingUsage> findByVehicle_LicensePlateContaining(String licensePlate);
    
    // 按支付状态查询
    List<ParkingUsage> findByPaymentStatus(String paymentStatus);
    
    // 按使用类型查询
    List<ParkingUsage> findByUsageType(Integer usageType);
    
    // 组合查询：按小区ID和使用类型查询
    List<ParkingUsage> findByParking_Community_IdAndUsageType(Long communityId, Integer usageType);
    
    // 组合查询：按小区ID和支付状态查询
    List<ParkingUsage> findByParking_Community_IdAndPaymentStatus(Long communityId, String paymentStatus);

    long countByUsageType(String usageType);
} 